$(function () {
    // +----------------------------------------------
    // 状态管理
    $('.user_status').on('click',function () {
        var that = $(this),
            status = that.is(':checked'),
            b = that.parents('.lyear-switch').find('b');
        if (status){
            b.html('&nbsp;&nbsp;启用');
            that.attr('data-status',1);
            $('#status').val(1);
        }else {
            b.html('&nbsp;&nbsp;已禁用');
            that.attr('data-status',0);
            $('#status').val(0);
        }
    });

    //------------------------------------------------
    //图片上传
    $('.upload_file_button').on('click',function () {
        $('#example-file-input').trigger('click');
    });

    //预览图片
    $('#example-file-input').on('change',function () {
        var file = this.files[0];//获取文件信息
        if (window.FileReader) {
            var reader = new FileReader();
            reader.readAsDataURL(file);
            //监听文件读取结束后事件
            reader.onloadend = function (e) {
                $(".upload_file_button").css({"background-image":'url('+e.target.result+')','background-size':'100% 100%'});
            };
        }
    });
});